package com.zxj.shop.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxj.shop.admin.entity.Member;
import com.zxj.shop.admin.entity.MsgRecord;
import com.zxj.shop.admin.service.MemberService;
import com.zxj.shop.admin.service.MsgService;
import com.zxj.shop.admin.vo.PageBean;
import com.zxj.shop.admin.vo.PageVO;
import com.zxj.shop.admin.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "会员管理")
@RestController
@RequestMapping("/api/admin/member")
public class MemberApiController {

    @Autowired
    MemberService memberService;
    @Autowired
    MsgService    msgService;

    @ApiOperation(value = "会员列表")
    @GetMapping("/list")
    public PageVO<Member> list(PageBean pageBean) {
        IPage<Member> logLoginPage = memberService.page(new Page<>(pageBean.getPage(), pageBean.getLimit()));
        return PageVO.pageVO(logLoginPage.getRecords(), logLoginPage.getTotal());
    }

    @ApiOperation(value = "短信列表")
    @GetMapping("/message")
    public PageVO<MsgRecord> message(MsgRecord msgRecord,PageBean pageBean) {
        IPage<MsgRecord> logLoginPage = msgService.page(new Page<>(pageBean.getPage(), pageBean.getLimit()),msgRecord);
        return PageVO.pageVO(logLoginPage.getRecords(), logLoginPage.getTotal());
    }

    @PostMapping("/view")
    @ApiOperation(value = "会员详情")
    public ResultVO<Member> view(@RequestParam(required = false) String userId) {
        return ResultVO.success(memberService.getMemberById(userId));
    }
}
